import {createRouter, createWebHashHistory} from "vue-router";
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            meta: {
                title: '登录'
            },
            component: () => import('../views/Login.vue')
        }, {
            path: '/login',
            redirect: '/'
        },
        {
            path: '/index',
            meta: {
                title: 'dashboard'
            },
            component: () => import('../views/Index.vue'),
            children: [
                {
                    path: '',//设置为空，默认展示
                    meta: {title: "首页"},
                    component: () => import('../views/top/Home.vue')
                },
                {
                    path: 'mail',
                    meta: {title: "邮件"},
                    component: () => import('../views/top/Mail.vue')
                },
                {
                    path: 'message',
                    meta: {title: "消息"},
                    component: () => import('../views/top/Message.vue')
                },
                //---------
                {
                    path: 'mine',
                    meta: {title: "个人中心"},
                    component: () => import('../views/user/Mine.vue')
                },
                {
                    path: 'user',
                    meta: {title: "用户管理"},
                    component: () => import('../views/user/User.vue')
                },
                {
                    path: 'setPassword',
                    meta: {title: "修改密码"},
                    component: () => import('../views/user/SetPassword.vue')
                },
                {
                    path: 'role',
                    meta: {title: "角色管理"},
                    component: () => import('../views/user/Role.vue')
                },
                //---------
                {
                    path: 'roomType',
                    meta: {title: "房型管理"},
                    component: () => import('../views/room/RoomType.vue')
                },
                {
                    path: 'room',
                    meta: {title: "房间管理"},
                    component: () => import('../views/room/Room.vue')
                },
                //---------
                {
                    path: 'livein',
                    meta: {title: "入住管理"},
                    component: () => import('../views/custom/LiveIn.vue')
                },
                {
                    path: 'order',
                    meta: {title: "订单管理"},
                    component: () => import('../views/custom/Order.vue')
                },
                //---------
                {
                    path: 'menu',
                    meta: {title: "菜单管理"},
                    component: () => import('../views/system/Menu.vue')
                },
                {
                    path: 'dictionary',
                    meta: {title: "字典管理"},
                    component: () => import('../views/system/Dictionary.vue')
                },
            ]
        }
    ]
})
router.beforeEach(function (_, __, next) {
    Nprogress.start()
    next()
})
router.afterEach(function (to, _) {
    if (to.meta && to.meta.title) {
        Nprogress.done()
        document.title = to.meta.title.toString()
    }
})
export default router